var summaryTableOption = {
    url: 'getAllTestData',
    queryParams: function (params) {
        return {
            pageNumber: params.pageNumber,
            pageSize: params.pageSize,
        }
    },
    columns: [
        {title: '序号', formatter: 'increasesWithZero'},
        {field: 'testShortStr', title: '充电站名称'},
        {field: 'testBigInt', title: '总充电量(度)'},
        {field: 'testDouble', title: '总充电费用(元)'}
    ],
    responseHandler: function (data) {
        return data;
    }
};

var detailsTableOption = {
    url: 'getAllTestData',
    queryParams: function (params) {
        return {
            pageNumber: params.pageNumber,
            pageSize: params.pageSize,
        }
    },
    detailView: true,
    detailFormatter: function (index, row) {
        var html = [];
        html.push('<span>【尖1】</span>');
        html.push('<span>时间：' + timestamp2datetime(row["testDateTime"]) + ' 至 ' + timestamp2datetime(row["testDateTime"]) + '&nbsp&nbsp</span>');
        html.push('<span>充电时长：' + row["testSmallInt"] + '分' + row["testSmallInt"] + '秒' + '&nbsp&nbsp</span>');
        html.push('<span>电表数：' + row["testBigInt"] + ' - ' + row["testBigInt"] + '&nbsp&nbsp</span>');
        html.push('<span>充电量(度)：' + row["testDouble"] + '&nbsp&nbsp</span>');
        html.push('<span>充电金额(元)：' + row["testDouble"] + '</span>');
        html.push("<br />");
        html.push('<span>【尖2】</span>');
        html.push('<span>时间：' + timestamp2datetime(row["testDateTime"]) + ' 至 ' + timestamp2datetime(row["testDateTime"]) + '&nbsp&nbsp</span>');
        html.push('<span>充电时长：' + row["testSmallInt"] + '分' + row["testSmallInt"] + '秒' + '&nbsp&nbsp</span>');
        html.push('<span>电表数：' + row["testBigInt"] + ' - ' + row["testBigInt"] + '&nbsp&nbsp</span>');
        html.push('<span>充电量(度)：' + row["testDouble"] + '&nbsp&nbsp</span>');
        html.push('<span>充电金额(元)：' + row["testDouble"] + '</span>');
        html.push("<br />");
        html.push('<span>【峰】&nbsp&nbsp</span>');
        html.push('<span>时间：' + timestamp2datetime(row["testDateTime"]) + ' 至 ' + timestamp2datetime(row["testDateTime"]) + '&nbsp&nbsp</span>');
        html.push('<span>充电时长：' + row["testSmallInt"] + '分' + row["testSmallInt"] + '秒' + '&nbsp&nbsp</span>');
        html.push('<span>电表数：' + row["testBigInt"] + ' - ' + row["testBigInt"] + '&nbsp&nbsp</span>');
        html.push('<span>充电量(度)：' + row["testDouble"] + '&nbsp&nbsp</span>');
        html.push('<span>充电金额(元)：' + row["testDouble"] + '</span>');
        return html.join('');
    },
    columns: [
        {title: '序号', formatter: 'increasesWithZero'},
        {field: 'testID', title: '订单号'},
        {field: 'testBigInt', title: '用户'},
        {field: 'testBigInt', title: '预付款(元)'},
        {field: 'testShortStr', title: '运营商'},
        {field: 'testShortStr', title: '充电站名称'},
        {field: 'testLongStr', title: '充电桩名称'},
        {field: 'testShortStr', title: '充电时长'},
        {field: 'testShortStr', title: '充电量(度)'},
        {field: 'testSmallInt', title: '充电金额(元)'},
        {field: 'testSmallInt', title: '服务费(元)'},
        {field: 'testSmallInt', title: '退款金额(元)'},
        {field: 'testSmallInt', title: '折扣金额(元)'},
        {field: 'testShortStr', title: '退款状态'},
        {field: 'testDateTime', title: '开始充电时间', formatter:'timestamp2datetime'},
        {field: 'testDateTime', title: '结束充电时间', formatter:'timestamp2datetime'},
        {field: 'testSmallInt', title: '开始电表数'},
        {field: 'testSmallInt', title: '结束电表数'},
        {
            title: '尖峰平谷',
            formatter: function (value, row, index) {
                return '<a class="detail-icon table-operate>' +
                    '<i class="glyphicon glyphicon-plus icon-plus>查看</i>' +
                    '</a>';
            }
        }
    ],
    responseHandler: function (data) {
        return data;
    },
    onLoadSuccess: function(data){
        $("#monthlyBillCheckTable td:first-child").remove();
    }
};

$(document).ready(function () {
    showSummary();

    laydate({
        elem:"#startTime",
        event:"focus",
        istoday: false,     // 是否显示今天
        issure: false,       // 是否显示确认
        max: laydate.now()
    });

    $("#startTime").focus(function () {
        setLaydateWidth(this);
    });
});

/* 显示总览表格 */
function showSummary() {
    /* 改变按钮样式 */
    $("#detailsBtn").addClass("button-white");
    $("#detailsBtn").removeClass("button-green");
    $("#summaryBtn").addClass("button-green");
    $("#summaryBtn").removeClass("button-white");

    $("#monthlyBillCheckTable").bootstrapTable('destroy');

    /* 更改表格内容 */
    setBootstrapTable('#monthlyBillCheckTable', summaryTableOption);
}

/* 显示详细列表表格 */
function showDetails() {
    /* 改变按钮样式 */
    $("#summaryBtn").addClass("button-white");
    $("#summaryBtn").removeClass("button-green");
    $("#detailsBtn").addClass("button-green");
    $("#detailsBtn").removeClass("button-white");

    $("#monthlyBillCheckTable").bootstrapTable('destroy');

    /* 更改表格内容 */
    setBootstrapTable('#monthlyBillCheckTable', detailsTableOption);

    /* 移除表格第一列 */
    $("#monthlyBillCheckTable th:first-child").remove();

}

/* 自适应输入框的宽度 */
function setLaydateWidth(x) {

    var width = $(x).outerWidth();
    if (width < 240)
        width = 240;

    var cssStr = "width:" + width + "px !important;";
    $("#laydate_box").css("width", width);
    $("#laydate_table").css("cssText", cssStr);
}